package com.vehicle.controller;

import com.vehicle.bean.DataGridView;
import com.vehicle.bean.PageVo;
import com.vehicle.bean.ResultDto;
import com.vehicle.mapper.CarMapper;
import com.vehicle.pojo.Btype;
import com.vehicle.pojo.Car;
import com.vehicle.pojo.Repair;
import com.vehicle.pojo.RepairRecord;
import com.vehicle.service.RepairRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("repairRecord")
public class RepairRecordController extends DataTimeController{

    @Autowired
    private RepairRecordService repairRecordService;



    @RequestMapping("findAllRepairRecord")
    @ResponseBody
    public DataGridView findAllRepairRecord(Integer carid, PageVo pageVo) {
        return repairRecordService.findAllRepairRecord(carid, pageVo);
    }

    @RequestMapping("repairRecordAdd")
    @ResponseBody
    public ResultDto repairRecordAdd(RepairRecord repairRecord){
        return repairRecordService.addRepairRecord(repairRecord);
    }

    @RequestMapping("findAllBtype")
    @ResponseBody
    public List<Btype> findAllBtype(){
        return repairRecordService.findAllRepairBtype();
    }

    @RequestMapping("findAllCar")
    @ResponseBody
    public List<Car> findAllCar(){
        return repairRecordService.findAllCar();
    }

    @RequestMapping("findAllRepair")
    @ResponseBody
    public List<Repair> findAllRepair(){
        return repairRecordService.findAllRepair();
    }

    @RequestMapping("deleteIds")
    @ResponseBody
    public ResultDto deleteIds(String idArray,String carid){
        return repairRecordService.delManyRepairRecord(idArray,carid);
    }

    @RequestMapping("repairRecordDelete")
    @ResponseBody
    public ResultDto repairRecordDelete(Integer repairid,Integer carid){
        return  repairRecordService.delRepairRecord(repairid,carid);
    }

    @RequestMapping("repairRecordEdit")
    @ResponseBody
    public ModelAndView repairRecordEdit(Integer repairid){
        ModelAndView modelAndView = new ModelAndView();
        RepairRecord repairRecord = repairRecordService.findRecordById(repairid);
        List<Btype> repairBtype = repairRecordService.findAllRepairBtype();
        modelAndView.setViewName("/page/car/RepairRecordEdit.jsp");
        modelAndView.addObject("repairRecord",repairRecord);
        modelAndView.addObject("repairBtype",repairBtype);
        return modelAndView;
    }

    @RequestMapping("doRepairRecordEdit")
    @ResponseBody
    public ResultDto doRepairRecordEdit(RepairRecord repairRecord){
        return repairRecordService.updateRecord(repairRecord);
    }

    @RequestMapping("bringCar")
    @ResponseBody
    public ModelAndView bringCar(Integer repairid){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("/page/car/RepairRecordBringCar.jsp");
        RepairRecord repairRecord = repairRecordService.findRecordById(repairid);
        modelAndView.addObject("repairRecord",repairRecord);
        List<Btype> repairBtype = repairRecordService.findAllRepairBtype();
        modelAndView.addObject("repairBtype",repairBtype);
        List<Repair> repair = repairRecordService.findAllRepair();
        modelAndView.addObject("repair",repair);
        return modelAndView;
    }
    @RequestMapping("doBringCar")
    @ResponseBody
    public ResultDto doBringCar(RepairRecord repairRecord){
        return repairRecordService.bringCar(repairRecord);
    }

    @RequestMapping("repairRecordCheck")
    public ModelAndView repairRecordCheck(Integer repairid){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("/page/car/RepairRecordCheck.jsp");
        RepairRecord repairRecord = repairRecordService.findRecordById(repairid);
        modelAndView.addObject("repairRecord",repairRecord);
        return modelAndView;
    }


}
